<?php

namespace App\Jobs\User;

use App\Models\Posts\WxComment;
use App\Models\Used\WxUsedComment;
use App\Models\User\WxUser;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class UpdateUserAnonymousInfoJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $uid = 0;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($uid)
    {
        //
        $this->uid = $uid;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
        if(_empty_($this->uid) || $this->uid > 0){
            return;
        }
        $user = WxUser::find(_abs($this->uid));
        if(_empty_($user)){
            _logger_(__file__,__line__, '查找用户失败' . $this->uid);
            return;
        }

        $user_name = $user->anonymous_name;
        $user_avatar = $user->anonymous_avatar;

        WxComment::where('user_id',abs($this->uid))->where('is_anonymous', 1)->update([
            'user_name' => $user_name,
            'user_avatar' => $user_avatar
        ]);
        WxComment::where('comment_agent_id',abs($this->uid))->update([
            'comment_agent_name' => $user_name,
            'comment_agent_avatar' => $user_avatar
        ]);
    }
}
